import { ComponentInfoType } from './index'

/**
 * 计算删除后的组件选中的selectId
 */
export function getNextSelectId(fe_id: string, componentList: ComponentInfoType[]) {
  const visComponents = componentList.filter(c => !c.isHidden)
  const index = visComponents.findIndex(c => c.fe_id === fe_id)
  if (index < 0) return ''

  let newSelectId = ''
  const length = visComponents.length
  if (length <= 1) {
    newSelectId = ''
  } else {
    if (index + 1 === length) {
      newSelectId = visComponents[index - 1].fe_id
    } else {
      newSelectId = visComponents[index + 1].fe_id
    }
  }

  return newSelectId
}
